// pages/about/index.js
var util = require('../../utils/util.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mobile: "",
    phone: "",
    fax: "",
    qq: "",
    address: "",
    location: "",
    latitudes: "",
    longitudes: "",
    name: "",
    isAiweapp: true,
    cardInfo: {}
  },

  tapchat: function() {
    var cardInfo = this.data.cardInfo.CardInfo;
    util.toChat(cardInfo);
    // wx.navigateTo({
    //   url: '/pages/weijieke/Business/Business?seltoid=' + cardInfo.Uid + '&name=' + cardInfo.Name,
    // })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    that.about();
    util.isAccredit(function (isAccredit) {
      that.setData({
        isAccredit: isAccredit
      })
    });
  },
  //是否授权登陆
  toShowToast: function () {
    let back = '/pages/kefu/index';
    wx.navigateTo({
      url: '../accredit/index?back=' + back,
    })
  },
  callphone: function(e) {
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.dataset.phone,
      success: function(res) {
        console.log(res);
      },
      fail: function(err) {
        console.log(err);
      },
      complete: function(res) {
        console.log(res);
      },
    })
  },
  callmobile: function(e) {
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.dataset.mobile,
      success: function(res) {
        console.log(res);
      },
      fail: function(err) {
        console.log(err);
      },
      complete: function(res) {
        console.log(res);
      },
    })
  },
  toMap: function() {
    wx.navigateTo({
      url: '/pages/map/index?location=' + this.data.location,
    })
  },
  //客服
  about: function() {
    var that = this;
    wx.request({
      url: app.globalData.host + '/api/store/GetInfo?id=' + app.globalData.storeId,
      success: function(res) {
        var Mobile = res.data.Data.Mobile
        var Phone = res.data.Data.Phone
        var Fax = res.data.Data.Fax
        var QQ = res.data.Data.QQ
        var name = res.data.Data.Name
        var Address = res.data.Data.Address
        var Location = res.data.Data.Location
        var latitudes = Location.substring(0, Location.indexOf(',')); //	纬度
        var locations2 = Location.substring(Location.indexOf(','));
        var longitudes = locations2.slice(1) //经度
        latitudes = parseFloat(latitudes)
        longitudes = parseFloat(longitudes)
        that.data.latitudes = latitudes;
        that.data.longitudes = longitudes;
        that.setData({
          mobile: Mobile,
          phone: Phone,
          fax: Fax,
          qq: QQ,
          name: name,
          address: Address
        })
      }
    })
  },
  //地图导航
  openMap: function() {
    var that = this;
    wx.showModal({
      title: '提示',
      content: '是否打开地图导航',
      success: function(res) {
        if (res.confirm) {
          wx.getLocation({
            type: 'gcj02', //返回可以用于wx.openLocation的经纬度
            success: function(res) {
              var latitude = res.latitude
              var longitude = res.longitude
              wx.openLocation({
                latitude: that.data.latitudes,
                longitude: that.data.longitudes,
                scale: 28,
                name: "点击右边打开地图导航",
                address: that.data.address
              })
            }
          })
        } else if (res.cancel) {

        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.getAiCardInfo()
  },

  // 获取名片信息
  getAiCardInfo: function() {
    var that = this;
    var cardId = wx.getStorageSync("cardId")
    if (cardId) {
      wx.request({
        url: app.globalData.host + '/api/BusinessCard/GetAiCard?uid=' + app.globalData.userInfo.Uid + '&staffId=' + cardId,
        success: function(res) {
          if (res.data.Code == 0) {
            that.setData({
              cardInfo: res.data.Data
            })
          }
        },
      })
    }
  },
})